using System;
using System.Collections.Generic;
using System.IO;
using IronMis2.Models;
using NHibernate.Expression;
using Castle.MonoRail.Framework;
using Castle.ActiveRecord.Framework.Validators;

namespace IronMis2.Controllers
{
    public class IncomeController:BaseController
    {
        public void In_come()
        {
            PropertyBag["incomes"] = Income.FindAll();
        }
        public void IncomeEdit(Guid id)
        {
            PropertyBag["income"] = Income.Find(id);
            PropertyBag["employees"] = Employee.FindAll();
            PropertyBag["departments"] = Department.FindAll();
            RenderView("IncomeDetail");
        }
        public void IncomeUpdate([DataBind("income")] Income income)
        {
            income.UpdateAndFlush();
            RedirectToAction("In_come");
        }
        public void IncomeDelete(Guid id)
        {
            Income.Find(id).DeleteAndFlush();
            PropertyBag["incomes"] = Income.FindAll();
            RedirectToAction("In_come");
        }
        public void IncomeAdd()
        {
            PropertyBag["employees"] = Employee.FindAll();
            PropertyBag["departments"] = Department.FindAll();
        }
        public void IncomeNew([DataBind("income")]Income income)
        {
            income.CreateAndFlush();
            PropertyBag["incomes"] = Income.FindAll();
            RedirectToAction("In_come");
        }
        public void IncomeItem(Guid id)
        {
            PropertyBag["income"] = Income.Find(id);
            RenderView("IncomeItems");
        }
        public void ItemEdit(Guid id)
        {
            PropertyBag["item"] = Item.Find(id);
            PropertyBag["incomes"] = Income.FindAll();
            RenderView("ItemDetails");
        }
        public void ItemSave([DataBind("item")]Item item)
        {
            item.UpdateAndFlush();
            PropertyBag["income"] = Income.Find(item.Income.Id);
            RenderView("IncomeItems");
        }
        public void ItemDelete(Guid id)
        {
            PropertyBag["income"] = Item.Find(id).Income;
            Item.Find(id).DeleteAndFlush();
            RenderView("IncomeItems");
        }
        public void ItemAdd(Guid id)
        {
            PropertyBag["income"] = Income.Find(id);
        }
        public void ItemNew([DataBind("item")]Item item)
        {
            item.CreateAndFlush();
            PropertyBag["income"] = Income.Find(item.Income.Id);
            RenderView("IncomeItems");
        }
    }
}
